package org.bing.engine.common.graniteds;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DomainAmfServlet extends SecurityAmfServlet {
    private static final long serialVersionUID = 1978;

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String uri = request.getRequestURI();
        if (uri != null && uri.endsWith("crossdomain.xml")) {
            response.addHeader("Content-Type", "application/xml");
            response.addHeader("X-Permitted-Cross-Domain-Policies", "all");
            PrintWriter out = response.getWriter();
            out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            out.println("<!DOCTYPE cross-domain-policy SYSTEM \"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd\" >");
            out.println("<cross-domain-policy> ");
            // out.println(" <site-control permitted-cross-domain-policies=\"all\" />  ");
            out.println(" <allow-access-from domain=\"*\" />  ");
            out.println(" <allow-http-request-headers-from domain=\"*\" headers=\"*\" />  ");
            out.println("</cross-domain-policy> ");
            out.flush();
        } else {
            super.doPost(request, response);
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String uri = request.getRequestURI();
        if (uri != null && uri.endsWith("crossdomain.xml")) {
            this.doPost(request, response);
        }
    }
 
}
